#include<bits/stdc++.h>
using namespace std;
int T;
int n;
int sa[1000005];
int rk[1000005];
int father[1000005],minn[1000005];
int gen(int x)
{
    if(x==father[x])
    {
        return x;
    }
    return father[x]=gen(father[x]);
}
void connect(int x,int y)
{
    int g1=gen(x),g2=gen(y);
    if(g1==g2)
    {
        return;
    }
    father[g1]=g2;
    minn[g2]=min(minn[g2],minn[g1]);
}
vector<pair<int,int> >nott;
vector<int>v[1000005];
char ans[1000005];
bool flag=0;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    freopen("string.in","r",stdin);
    freopen("string.out","w",stdout);
    cin>>T;
    while(T--)
    {
        flag=0;
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            cin>>sa[i];
            sa[i]++;
            rk[sa[i]]=i;
        }
        nott.clear();
        for(int i=1;i<=n;i++)
        {
            v[i].clear();
            ans[i]=0;
        }
        for(int i=1;i<=n;i++)
        {
            father[i]=i;
            minn[i]=rk[i];
        }
        int maxx=0;
        for(int i=1;i<2*n;i++)
        {
            int x;
            cin>>x;
            //cout<<"x="<<x<<endl;
            if(flag)
            {
                continue;
            }
            if(i%2==1)
            {
                if(x%2==0)
                {
                    flag=1;
                    continue;
                }
                int l=(i+1)/2-x/2,r=(i+1)/2+x/2;
                //cout<<"::"<<l<<" "<<r<<endl;
                if(l<=0||r>n)
                {
                    flag=1;
                    continue;
                }
                if(r>maxx)
                {
                    for(int j=maxx+1;j<=r;j++)
                    {
                        connect(j,l+r-j);
                        //cout<<"!!"<<j<<"="<<l+r-j<<endl;
                    }
                    maxx=max(maxx,r);
                }
                if(l-1!=0&&r+1!=n+1)
                {
                    nott.push_back(make_pair(l-1,r+1));
                }
            }
            else
            {
                if(x%2==1)
                {
                    flag=1;
                    continue;
                }
                int l=i/2-x/2+1,r=i/2+1+x/2-1;
                //cout<<"??"<<l<<" "<<r<<endl;
                if(l<=0||r>n)
                {
                    flag=1;
                    continue;
                }
                if(r>maxx)
                {
                    for(int j=maxx+1;j<=r;j++)
                    {
                        connect(j,l+r-j);
                        //cout<<"!!"<<j<<"="<<l+r-j<<endl;
                    }
                    maxx=max(maxx,r);
                }
                if(l-1!=0&&r+1!=n+1)
                {
                    nott.push_back(make_pair(l-1,r+1));
                }
            }
        }
        if(flag==1)
        {
            cout<<-1<<endl;
            continue;
        }
        for(int i=n;i>1;i--)
        {
            int g=gen(sa[i]);
            if(minn[g]<i)
            {
                connect(sa[i],sa[i-1]);
            }
        }
        for(int i=0;i<nott.size();i++)
        {
            if(gen(nott[i].first)==gen(nott[i].second))
            {
                flag=1;
                break;
            }
            v[gen(nott[i].first)].push_back(gen(nott[i].second));
            v[gen(nott[i].second)].push_back(gen(nott[i].first));
        }
        if(flag)
        {
            cout<<-1<<endl;
            continue;
        }
        int r;
        for(int l=1;l<=n;l=r+1)
        {
            int g1=gen(sa[l]);
            for(r=l;r<=n;r++)
            {
                if(gen(sa[r])!=g1)
                {
                    break;
                }
            }
            r--;
            if(l==1)
            {
                ans[g1]='a';
                continue;
            }
            int lastg=gen(sa[l-1]);
            for(int i=0;i<v[g1].size();i++)
            {
                if(ans[lastg]==ans[v[g1][i]])
                {
                    ans[g1]=ans[lastg]+1;
                    break;
                }
            }
            if(rk[sa[l-1]+1]>rk[sa[l]+1])
            {
                ans[g1]=ans[lastg]+1;
            }
            if(ans[g1]==0)
            {
                ans[g1]=ans[lastg];
            }
            for(int i=l+1;i<=r;i++)
            {
                if(rk[sa[i-1]+1]>rk[sa[i]+1])
                {
                    flag=1;
                    break;
                }
            }
            if(flag)
            {
                break;
            }
        }
        if(flag)
        {
            cout<<-1<<endl;
            continue;
        }
        for(int i=1;i<=n;i++)
        {
            cout<<ans[gen(i)];
        }
        cout<<endl;
    }
    return 0;
}
